/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.matheval;
import simhya.matheval.function.FunctionDefinition;
/**
 *
 * @author Luca
 */
public class BinaryFunctionNode extends FunctionNode {

    public BinaryFunctionNode(FunctionDefinition function) {
        super(function,2);
    }
    @Override
    void computeValue() {
        children[0].computeValue();
        children[1].computeValue();
        super.value = function.compute(children[0].value,children[1].value);
    }

    @Override
    void computeValue(SymbolArray varReference) {
        children[0].computeValue(varReference);
        children[1].computeValue(varReference);
        super.value = function.compute(children[0].value,children[1].value);
    }

    @Override
    void computeValue(int evaluationCode) {
        if (random || super.evaluationCode != evaluationCode) {
            super.evaluationCode = evaluationCode;
            children[0].computeValue(evaluationCode);
            children[1].computeValue(evaluationCode);
            super.value = function.compute(children[0].value,children[1].value);
        }
    }

    @Override
    void computeValue(SymbolArray varReference, int evaluationCode) {
        if (random || super.evaluationCode != evaluationCode) {
            super.evaluationCode = evaluationCode;
            children[0].computeValue(varReference,evaluationCode);
            children[1].computeValue(varReference,evaluationCode);
            super.value = function.compute(children[0].value,children[1].value);
        }
    }

}
